home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / windows / wdj1096.zip / ZOLMAN.ZIP / DRAW.ZIP / DRAWCTL.CPP < prev    next >
C/C++ Source or Header  |  1996-05-22  |  8KB  |  279 lines

  1. // DrawCtl.cpp : Implementation of the CDrawCtrl OLE control class.
  2.  
  3. #include "stdafx.h"
  4. #include "Draw.h"
  5. #include "ParkWnd.h"
  6. #include "DrawCtl.h"
  7. #include "DrawPpg.h"
  8.  
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16.  
  17. IMPLEMENT_DYNCREATE(CDrawCtrl, COleControl)
  18.  
  19. #define ID_BUTTON    1000
  20. #define ID_EDIT        1001
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Message map
  24.  
  25. BEGIN_MESSAGE_MAP(CDrawCtrl, COleControl)
  26.     //{{AFX_MSG_MAP(CDrawCtrl)
  27.     ON_WM_CREATE()
  28.     ON_WM_SIZE()
  29.     //}}AFX_MSG_MAP
  30.     ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
  31.     ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  32. END_MESSAGE_MAP()
  33.  
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Dispatch map
  37.  
  38. BEGIN_DISPATCH_MAP(CDrawCtrl, COleControl)
  39.     //{{AFX_DISPATCH_MAP(CDrawCtrl)
  40.     // NOTE - ClassWizard will add and remove dispatch map entries
  41.     //    DO NOT EDIT what you see in these blocks of generated code !
  42.     //}}AFX_DISPATCH_MAP
  43.     DISP_FUNCTION_ID(CDrawCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  44. END_DISPATCH_MAP()
  45.  
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Event map
  49.  
  50. BEGIN_EVENT_MAP(CDrawCtrl, COleControl)
  51.     //{{AFX_EVENT_MAP(CDrawCtrl)
  52.     // NOTE - ClassWizard will add and remove event map entries
  53.     //    DO NOT EDIT what you see in these blocks of generated code !
  54.     //}}AFX_EVENT_MAP
  55. END_EVENT_MAP()
  56.  
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Property pages
  60.  
  61. // TODO: Add more property pages as needed.  Remember to increase the count!
  62. BEGIN_PROPPAGEIDS(CDrawCtrl, 1)
  63.     PROPPAGEID(CDrawPropPage::guid)
  64. END_PROPPAGEIDS(CDrawCtrl)
  65.  
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Initialize class factory and guid
  69.  
  70. IMPLEMENT_OLECREATE_EX(CDrawCtrl, "DRAW.DrawCtrl.1",
  71.     0x23c3763, 0xb40a, 0x11cf, 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94)
  72.  
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Type library ID and version
  76.  
  77. IMPLEMENT_OLETYPELIB(CDrawCtrl, _tlid, _wVerMajor, _wVerMinor)
  78.  
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // Interface IDs
  82.  
  83. const IID BASED_CODE IID_DDraw =
  84.         { 0x23c3761, 0xb40a, 0x11cf, { 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94 } };
  85. const IID BASED_CODE IID_DDrawEvents =
  86.         { 0x23c3762, 0xb40a, 0x11cf, { 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94 } };
  87.  
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Control type information
  91.  
  92. static const DWORD BASED_CODE _dwDrawOleMisc =
  93.     OLEMISC_ACTIVATEWHENVISIBLE |
  94.     OLEMISC_SETCLIENTSITEFIRST |
  95.     OLEMISC_INSIDEOUT |
  96.     OLEMISC_CANTLINKINSIDE |
  97.     OLEMISC_RECOMPOSEONRESIZE;
  98.  
  99. IMPLEMENT_OLECTLTYPE(CDrawCtrl, IDS_DRAW, _dwDrawOleMisc)
  100.  
  101.  
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CDrawCtrl::CDrawCtrlFactory::UpdateRegistry -
  104. // Adds or removes system registry entries for CDrawCtrl
  105.  
  106. BOOL CDrawCtrl::CDrawCtrlFactory::UpdateRegistry(BOOL bRegister)
  107. {
  108.     if (bRegister)
  109.         return AfxOleRegisterControlClass(
  110.             AfxGetInstanceHandle(),
  111.             m_clsid,
  112.             m_lpszProgID,
  113.             IDS_DRAW,
  114.             IDB_DRAW,
  115.             TRUE,                       //  Insertable
  116.             _dwDrawOleMisc,
  117.             _tlid,
  118.             _wVerMajor,
  119.             _wVerMinor);
  120.     else
  121.         return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  122. }
  123.  
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CDrawCtrl::CDrawCtrl - Constructor
  127.  
  128. CDrawCtrl::CDrawCtrl()
  129. {
  130.     InitializeIIDs(&IID_DDraw, &IID_DDrawEvents);
  131.  
  132.     // TODO: Initialize your control's instance data here.
  133. }
  134.  
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CDrawCtrl::~CDrawCtrl - Destructor
  138.  
  139. CDrawCtrl::~CDrawCtrl()
  140. {
  141.     // TODO: Cleanup your control's instance data here.
  142. }
  143.  
  144.  
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CDrawCtrl::OnDraw - Drawing function
  147.  
  148. void CDrawCtrl::OnDraw(
  149.             CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  150. {
  151.     // TODO: Replace the following code with your own drawing code.
  152.     //pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
  153.     //pdc->Ellipse(rcBounds);
  154.   if ( FALSE == IsWindowVisible() )
  155.   {
  156.     CWnd* pWndContainer = pdc->GetWindow();
  157.     if ( pWndContainer )
  158.     {
  159.       if ( NULL == m_wndParkingWnd.GetSafeHwnd() )
  160.       {
  161.         DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  162.         if ( FALSE == m_wndParkingWnd.CreateEx ( 
  163.                     WS_EX_CLIENTEDGE, 
  164.               NULL, 
  165.               NULL, 
  166.               dwStyle,
  167.                   rcBounds.left, 
  168.               rcBounds.top,
  169.                     rcBounds.Width(), 
  170.               rcBounds.Height(),
  171.                     pWndContainer->m_hWnd, 
  172.               0)) 
  173.         return;
  174.       }
  175.  
  176.       if (m_wndParkingWnd.m_hWnd != NULL)
  177.             m_wndParkingWnd.ShowWindow(SW_SHOW);
  178.  
  179.       m_btnButton.SetParent ( &m_wndParkingWnd );
  180.       m_wndParkingWnd.pwndChild1 = (CWnd*)&m_btnButton;
  181.       m_btnButton.EnableWindow(FALSE);
  182.  
  183.       m_edEdit.SetParent ( &m_wndParkingWnd );
  184.       m_wndParkingWnd.pwndChild2 = (CWnd*)&m_edEdit;
  185.       m_edEdit.EnableWindow(FALSE);
  186.  
  187.       m_wndParkingWnd.MoveWindow ( rcBounds );
  188.     }
  189.   }
  190.   else
  191.   {
  192.     if ( NULL != m_wndParkingWnd.GetSafeHwnd() )
  193.     {
  194.       m_wndParkingWnd.ShowWindow(SW_HIDE);
  195.  
  196.       m_btnButton.SetParent (  this );
  197.       m_btnButton.EnableWindow(TRUE);
  198.       m_edEdit.SetParent ( this );
  199.       m_edEdit.EnableWindow(TRUE);
  200.  
  201.       m_wndParkingWnd.DestroyWindow();
  202.     }
  203.   }
  204. }
  205.  
  206.  
  207. /////////////////////////////////////////////////////////////////////////////
  208. // CDrawCtrl::DoPropExchange - Persistence support
  209.  
  210. void CDrawCtrl::DoPropExchange(CPropExchange* pPX)
  211. {
  212.     ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  213.     COleControl::DoPropExchange(pPX);
  214.  
  215.     // TODO: Call PX_ functions for each persistent custom property.
  216.  
  217. }
  218.  
  219.  
  220. /////////////////////////////////////////////////////////////////////////////
  221. // CDrawCtrl::OnResetState - Reset control to default state
  222.  
  223. void CDrawCtrl::OnResetState()
  224. {
  225.     COleControl::OnResetState();  // Resets defaults found in DoPropExchange
  226.  
  227.     // TODO: Reset any other control state here.
  228. }
  229.  
  230.  
  231. /////////////////////////////////////////////////////////////////////////////
  232. // CDrawCtrl::AboutBox - Display an "About" box to the user
  233.  
  234. void CDrawCtrl::AboutBox()
  235. {
  236.     CDialog dlgAbout(IDD_ABOUTBOX_DRAW);
  237.     dlgAbout.DoModal();
  238. }
  239.  
  240.  
  241. /////////////////////////////////////////////////////////////////////////////
  242. // CDrawCtrl message handlers
  243.  
  244. int CDrawCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  245. {
  246.     if (COleControl::OnCreate(lpCreateStruct) == -1)
  247.         return -1;
  248.     
  249.     // TODO: Add your specialized creation code here
  250.     
  251.     if ( FALSE == m_btnButton.Create ( 
  252.                          _T("Button"), 
  253.                          BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
  254.                          CRect ( 0, 0, lpCreateStruct->cx, lpCreateStruct->cy/2 ),
  255.                          this,
  256.                          ID_BUTTON ) )
  257.       return -1;
  258.  
  259.     if ( FALSE == m_edEdit.Create ( 
  260.                          ES_CENTER | WS_CHILD | WS_VISIBLE,
  261.                          CRect(0,lpCreateStruct->cy/2,lpCreateStruct->cx,lpCreateStruct->cy),
  262.                          this,
  263.                          ID_EDIT ) )
  264.       return -1;
  265.  
  266.     return 0;
  267. }
  268.  
  269. void CDrawCtrl::OnSize(UINT nType, int cx, int cy) 
  270. {
  271.     COleControl::OnSize(nType, cx, cy);
  272.     
  273.     // TODO: Add your message handler code here
  274.   m_btnButton.MoveWindow(0, 0, cx, cy /2);
  275.   m_edEdit.MoveWindow(0, cy/2, cx, cy);
  276.  
  277.  
  278.